<?php
/**
 * Created by PhpStorm.
 * User: zhu_hbo
 * Date: 16/10/8
 * Time: 下午4:22
 */

//PHP7+ 版本新增整除运算符 intdiv()
//var_dump(intdiv(10, 3));
//echo "<p>";
//$x = "hello";
//$x0 = "world";
//
//$x0 .= $x;
//echo $x0;
//echo "<p>";

$x = 100;
$y = "100";

var_dump($x == $y);
echo "<p>";

var_dump($x === $y);
echo "<p>";

var_dump($x != $y);
echo "<p>";

var_dump($x !== $y);
echo "<p>";

echo "==============================";
echo "<p>";
$a = 6;
$b = 3;
var_dump($a == 6 and $b == 3);

echo "==============================";
echo "<p>";

$c = array("a" => "red", "b" => "greed");
$d = array("c" => "blue", "d" => "yellow");
echo $c["a"];
echo "<p>";
var_dump($c);
echo "<p>";

//$x = array("a" => "red", "b" => "green");
//$y = array("c" => "blue", "d" => "yellow");
//$z = $x + $y; // $x 和 $y 数组合并
//var_dump($z);
//var_dump($x == $y);
//var_dump($x === $y);
//var_dump($x != $y);
//var_dump($x <> $y);
//var_dump($x !== $y);

// PHP_EOL 是一个换行符，兼容更大平台。
$test = "菜鸟教程";
// 普通写法
$username = isset($test) ? $test : "nobody";
echo $username, PHP_EOL;

// PHP 5.3+ 版本写法
$username = $test ?: "nobody";
echo $username, PHP_EOL;

// 如果 $_GET['user'] 不存在返回 'nobody'，否则返回 $_GET['user'] 的值
$username = $_GET['user'] ?? 'nobody';
// 类似的三元运算符
$username = isset($_GET['user']) ? $_GET['user'] : 'nobody';
echo "<p>";

// 组合比较符(PHP7+)
// 整型
echo 1 <=> 1; // 0
echo "<p>";
echo 1 <=> 2; // -1
echo "<p>";
echo 2 <=> 1; // 1
echo "<p>";

// 浮点型
echo 1.5 <=> 1.5; // 0
echo "<p>";
echo 1.5 <=> 2.5; // -1
echo "<p>";
echo 2.5 <=> 1.5; // 1
echo "<p>";

// 字符串
echo "a" <=> "a"; // 0
echo "<p>";
echo "a" <=> "b"; // -1
echo "<p>";
echo "b" <=> "a"; // 1
echo "<p>";

?>